<?php

namespace App\Model\form;

use App\Constants\ConstCode;
use App\Model\WeworkFriend;

trait WeworkFriendTrait
{
    /**
     * 获取好友详情
     * @param  $where
     * @return array
     */
    public function getWeworkFriend($where): array
    {
        $result = WeworkFriend::where($where)->first();
        return !empty($result) ? $result->toArray() : [];
    }

    /**
     * 获取好友详情
     * @param  $where
     */
    public function getWeworkFriendInfo($where)
    {
        return WeworkFriend::where($where)->first();
    }

    /**
     * 获取好友头像
     * @param  $where
     * @return string
     */
    public function getWeworkFriendPath($where): string
    {
        return WeworkFriend::where($where)->value('path');
    }

    /**
     * 获取好友列表
     */
    public function getWeworkFriendPage($where,$params): array
    {
        $query = WeworkFriend::where($where);
        $count = $query->count();
        $pageNum = $params['pageNum'] - 1;
        $list = $query->offset($pageNum * $params['pageSize'])
            ->limit($params['pageSize'])->orderByDesc('id')->get()->toArray();
        return ['count' => $count, 'list' => $list];
    }

}